package com.oocl.dataprocess.parser.Impl;

import java.io.File;
import java.util.ArrayList;
import java.util.Scanner;

import com.oocl.dataprocess.filter.Impl.FilterRex;
import com.oocl.dataprocess.parser.Parsers;
import com.oocl.dataprocess.pojo.Customer;


public class ParseTxT implements Parsers{
	Customer customer;
	private FilterRex filterRex;
	


	@SuppressWarnings("resource")
	public ArrayList<Customer> parseFromTxT(String src) {
		File file = new File(src);
		ArrayList<Customer> list = new ArrayList<Customer>();
		Scanner scan = null;
		try {  
            scan = new Scanner(file);
        } catch (Exception e) {  
        }  
        StringBuffer sb = new StringBuffer();  
        while (scan.hasNextLine()) {  
            sb.append(scan.nextLine().replaceAll("\\s{2,}", " ")).append("\n");  
        }
        String[] customersString = sb.toString().split("\n");
        
        for(String customerString:customersString){
        	String[] fileds = customerString.split(" ");
        	customer = new Customer(fileds[0], fileds[1], fileds[4], fileds[3], fileds[2]);
        	list.add(customer);
        }
        return list;
	}


}
